using System.Collections;
using System.Collections.Generic;

namespace MvvmBase.ViewModel
{
    public class ComplexEnumerator<T, T1, T2> : IEnumerator<T> where T1 : T where T2 : T
    {
        private readonly IEnumerator<T1> _enumerator1;
        private readonly IEnumerator<T2> _enumerator2;

        public ComplexEnumerator(IEnumerator<T1> enumerator1, IEnumerator<T2> enumerator2)
        {
            _enumerator1 = enumerator1;
            _enumerator2 = enumerator2;
        }

        #region IEnumerator<T> Members

        public bool MoveNext()
        {
            if (_enumerator1.MoveNext())
            {
                Current = _enumerator1.Current;
                return true;
            }
            bool result = _enumerator2.MoveNext();
            Current = _enumerator2.Current;
            return result;
        }

        public void Reset()
        {
            _enumerator1.Reset();
            _enumerator2.Reset();
        }

        public T Current { get; private set; }

        object IEnumerator.Current
        {
            get
            {
                return Current;
            }
        }

        public void Dispose()
        {
            _enumerator1.Dispose();
            _enumerator2.Dispose();
        }
        #endregion
    }
}